package com.lhc.kafkademo.producer;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

public class SamplePartition implements Partitioner {

    @Override
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {

        /**
         * key-1
         * key-2
         * key-3
         */
        String keyStr = key+"";
        String keyInt = keyStr.substring(4);
        System.out.println("KeyStr:"+keyStr+",KeyInt:"+keyInt);
        int i = Integer.parseInt(keyInt) % 2;
        return i;
    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
